home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / DbaseIII+ {Windows} / DISK6 / SAMPLES2.PAK / GETFLTS.WFM < prev    next >
Encoding:
Text File  |  1994-08-02  |  9.4 KB  |  290 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Getflts.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         5/93
  7. *
  8. *  UPDATED:      3/94
  9. *
  10. *  REVISION:     $Revision:   1.20  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This is a form called from Equipmnt.wfm that brings up a
  15. *                dialog which allows selecting AirBorland flights based on
  16. *                their origin, destination, and departure date.  This form
  17. *                has two listboxes -- originList and destList, and one
  18. *                spinbox -- dateSpin.  It also has Ok and Cancel buttons
  19. *                that respectively allow the selections to be saved or
  20. *                ignored.
  21. *
  22. *
  23. *  PARAMETERS:   None
  24. *
  25. *  CALLS:        Buttons.cc   (Custom controls file)
  26. *                Equipmnt.qbe (View of tables)
  27. *
  28. *  USAGE:        SET PROCEDURE TO GETFLTS.WFM
  29. *                LOCAL F
  30. *                F = NEW GETFLTS()
  31. *                F.READMODAL()
  32. *
  33. *******************************************************************************
  34. #include <Messdlg.h>
  35. #include "Equipmnt.h"
  36. set ldCheck off
  37.  
  38. ** END HEADER -- do not remove this line*
  39. * Generated on 06/01/94
  40. *
  41. LOCAL f
  42. f = NEW GETFLTSFORM()
  43. f.Open()
  44.  
  45. CLASS GETFLTSFORM OF FORM
  46.    Set Procedure to BUTTONS.CC Additive
  47.    this.Height =         17.61
  48.    this.HelpFile = ""
  49.    this.HelpId = ""
  50.    this.Text = "Flight Selection"
  51.    this.OnOpen = CLASS::ONOPEN
  52.    this.OnClose = CLASS::ONCLOSE
  53.    this.OnSelection = CLASS::ONSELECTION
  54.    this.ColorNormal = "N/0XFFFF80"
  55.    this.MousePointer =          1
  56.    this.Width =         71.26
  57.    this.Top =          2.20
  58.    this.Left =         17.16
  59.  
  60.    DEFINE IMAGE LOGOIMAGE OF THIS;
  61.        PROPERTY;
  62.          Height          5.78,;
  63.          Alignment          2,;
  64.          DataSource "FILE AIRBRLN2.BMP",;
  65.          Width         58.07,;
  66.          Top          0.00,;
  67.          Left          6.60
  68.  
  69.    DEFINE TEXT ORIGTEXT OF THIS;
  70.        PROPERTY;
  71.          Height          1.32,;
  72.          Text "Origin",;
  73.          ColorNormal "N/0XFFFF80",;
  74.          Border .F.,;
  75.          Width         19.80,;
  76.          Top          5.78,;
  77.          FontSize         10.00,;
  78.          Left          1.32
  79.  
  80.    DEFINE LISTBOX ORIGINLIST OF THIS;
  81.        PROPERTY;
  82.          Height          6.75,;
  83.          Value "",;
  84.          ColorNormal "N/W",;
  85.          ColorHighLight "W+/B",;
  86.          ID        800,;
  87.          Width         20.46,;
  88.          Top          7.09,;
  89.          FontSize         11.25,;
  90.          Left          0.99
  91.  
  92.    DEFINE TEXT DESTTEXT OF THIS;
  93.        PROPERTY;
  94.          Height          1.32,;
  95.          Text "Destination",;
  96.          ColorNormal "N/0XFFFF80",;
  97.          Border .F.,;
  98.          Width         19.80,;
  99.          Top          5.78,;
  100.          FontSize         10.00,;
  101.          Left         27.71
  102.  
  103.    DEFINE LISTBOX DESTLIST OF THIS;
  104.        PROPERTY;
  105.          Height          6.75,;
  106.          Value "",;
  107.          ColorNormal "N/W",;
  108.          ColorHighLight "W+/B",;
  109.          ID        800,;
  110.          Width         20.46,;
  111.          Top          7.09,;
  112.          FontSize         11.25,;
  113.          Left         27.38
  114.  
  115.    DEFINE TEXT DATETEXT OF THIS;
  116.        PROPERTY;
  117.          Height          1.32,;
  118.          Text "Date",;
  119.          ColorNormal "N/0XFFFF80",;
  120.          Border .F.,;
  121.          Width         14.52,;
  122.          Top          5.78,;
  123.          FontSize         10.00,;
  124.          Left         52.79
  125.  
  126.    DEFINE SPINBOX DATESPIN OF THIS;
  127.        PROPERTY;
  128.          Height          1.32,;
  129.          Function     "J",;
  130.          ColorNormal "N/W",;
  131.          Border .T.,;
  132.          ColorHighLight "W+/B",;
  133.          Width         17.82,;
  134.          Top          7.16,;
  135.          FontSize         11.25,;
  136.          Left         52.79,;
  137.          Rangemin    {01/01/90},;
  138.          Rangemax    {01/01/94},;
  139.          Value       {01/01/92}
  140.  
  141.    DEFINE OKBUTTON GETFLTSOKBUTTON OF THIS;
  142.        PROPERTY;
  143.          Height          1.50,;
  144.          Width         14.11,;
  145.          Top         14.87,;
  146.          Left         42.23
  147.  
  148.    DEFINE CANCELBUTTON GETFLTSCANCELBUTTON OF THIS;
  149.        PROPERTY;
  150.          OnClick .F.,;                   && OnSelection takes care of this
  151.          Height          1.50,;
  152.          Group .F.,;
  153.          ID          0,;
  154.          Width         14.11,;
  155.          Top         14.87,;
  156.          Left         56.75
  157.  
  158.    *******************************************************************************
  159.    procedure OnOpen
  160.    *******************************************************************************
  161.    set procedure to program(1) additive  && for functions located after class
  162.    set procedure to Sampproc additive    && for FormatStr function
  163.  
  164.    if type("originAr") = "U"
  165.  
  166.       public originAr,destAr             && if called stand alone, create vars
  167.       local curRecCnt
  168.       private tagName
  169.  
  170.       this.standAlone = .t.
  171.       this.view = "Equipmnt.qbe"
  172.       *** make arrays of unique origins and destinations
  173.       select flights
  174.       tagName = field(2) + "UN"
  175.       set order to &tagName   && origin unique
  176.       count to curRecCnt      && count of unique origins -- for declaring array
  177.  
  178.       declare originAr[curRecCnt,1]
  179.       declare destAr[curRecCnt,1]
  180.  
  181.       copy to array originAr field origin
  182.       tagName = field(3) + "UN"
  183.       set order to &tagName   && destination unique
  184.       count to curRecCnt   && count of unique destinations -- for declaring array
  185.       copy to array destAr field dest
  186.       tagName = field(1)
  187.       set order to &tagName   && don't need the index for a while
  188.       go top
  189.    else
  190.       this.standAlone = .f.
  191.    endif
  192.    this.originList.dataSource = "Array originAr"
  193.    this.destList.dataSource = "Array destAr"
  194.    this.dateSpin.value = flights->date
  195.  
  196.    *******************************************************************************
  197.    procedure OnClose
  198.    *******************************************************************************
  199.    if form.standAlone   && if not called from equipmnt.wfm
  200.       release originAr, destAr
  201.    endif
  202.    close procedure Buttons.cc, Sampproc.prg, program(1)
  203.  
  204.  
  205.    *******************************************************************************
  206.    procedure OnSelection (controlId)
  207.    *******************************************************************************
  208.    private originT, destT, dateT, filter, planeT, curTable, tryAgain, tagName
  209.  
  210.    tryAgain = .f.
  211.    *** if Cancel wasn't selected and if not running standalone
  212.    if controlId <> 0
  213.       * get the selected origin, destination
  214.       originT = ALLTRIM(form.originList.value)
  215.       destT =  ALLTRIM(form.destList.value)
  216.       dateT = form.dateSpin.value
  217.       filter = ""
  218.       *** longer, but looks cleaner with IF instead of IIF()
  219.       if .not. empty(originT)
  220.          filter = FormatStr("origin = %1", AddQuotes(originT))
  221.       endif
  222.       if .not. empty(destT)
  223.          if .not. empty(filter)
  224.             filter = FormatStr("%1 .and. dest = %2", filter, AddQuotes(destT))
  225.          else
  226.             filter = FormatStr("dest = %1", AddQuotes(destT))
  227.          endif
  228.       endif
  229.       if .not. empty(dateT)
  230.          if .not. empty(filter)
  231.             filter = FormatStr("%1 .and. date >= ctod(%2)", filter, AddQuotes(dtoc(dateT)))
  232.          else
  233.             filter = FormatStr("date >= ctod(%1)", AddQuotes(dtoc(dateT)))
  234.          endif
  235.       endif
  236.       * Check filter in another area, so form doesn't get updated unnecessarily
  237.       use dbf() in select() alias temp
  238.       select temp
  239.       set filter to &filter
  240.       go top
  241.       if eof()             && no flights match the selections made
  242.          if ConfirmationMessage(;
  243.             FormatStr("There are no flights from %1 to %2 on or after %3."+;
  244.                          chr(13) +;
  245.                          "Would you like to select another set of flights?",;
  246.                       originT, destT, dtoc(dateT)),;
  247.             "Confirmation") = YES
  248.             tryAgain = .t.             && flag to specify that form stays open
  249.          endif
  250.          select flights
  251.       else
  252.          select flights
  253.          set filter to &filter
  254.          go top
  255.          do case
  256.             case .not. empty(originT)  && if an origin was specified, index on
  257.                                        && origin, and look for selected origin
  258.                tagName = field(2)
  259.                set order to &tagName   && tag origin
  260.                seek originT
  261.             case .not. empty(destT)    && otherwise, if a destination was
  262.                tagName = field(3)      && specified, index on that, and seek.
  263.                set order to &tagName   && tag dest
  264.                seek destT
  265.  
  266.             otherwise                          && index on origin if no selection was
  267.                tagName = field(2)
  268.                set order to &tagName           && made, and go to the top of the database
  269.                go top
  270.          endcase
  271.       endif
  272.       use in temp
  273.    endif
  274.    if .not. tryAgain
  275.       form.Close()
  276.    endif
  277.  
  278. ENDCLASS
  279.  
  280. *******************************************************************************
  281. function AddQuotes( string )
  282.  
  283. * Add quotes to the parameter string.  This function is used when combining
  284. * several strings and macrosubstituting (&) the resulting string
  285. *******************************************************************************
  286. return "'" + string + "'"
  287.  
  288.  
  289.  
  290.